package com.ruoyi.system.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.OrderCategory;
import com.ruoyi.system.service.IOrderCategoryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 订单品类 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-08-07
 */
@Api("订单品类管理")
@Controller
@RequestMapping("/system/orderCategory")
public class OrderCategoryController extends BaseController
{
    private String prefix = "system/orderCategory";
	
	@Autowired
	private IOrderCategoryService orderCategoryService;
	
	@RequiresPermissions("system:orderCategory:view")
	@GetMapping()
	public String orderCategory()
	{
	    return prefix + "/orderCategory";
	}
	
	/**
	 * 查询订单品类列表
	 */
	@ApiOperation("查询订单品类列表")
	@RequiresPermissions("system:orderCategory:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(OrderCategory orderCategory)
	{
		startPage();
        List<OrderCategory> list = orderCategoryService.selectOrderCategoryList(orderCategory);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出订单品类列表
	 */
	@RequiresPermissions("system:orderCategory:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderCategory orderCategory)
    {
    	List<OrderCategory> list = orderCategoryService.selectOrderCategoryList(orderCategory);
        ExcelUtil<OrderCategory> util = new ExcelUtil<OrderCategory>(OrderCategory.class);
        return util.exportExcel(list, "orderCategory");
    }
	
	/**
	 * 新增订单品类
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存订单品类
	 */
	@ApiOperation("新增保存订单品类")
	@RequiresPermissions("system:orderCategory:add")
	@Log(title = "订单品类", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(OrderCategory orderCategory)
	{		
		return toAjax(orderCategoryService.insertOrderCategory(orderCategory));
	}

	/**
	 * 修改订单品类
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		OrderCategory orderCategory = orderCategoryService.selectOrderCategoryById(id);
		mmap.put("orderCategory", orderCategory);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存订单品类
	 */
	@ApiOperation("修改保存订单品类")
	@RequiresPermissions("system:orderCategory:edit")
	@Log(title = "订单品类", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(OrderCategory orderCategory)
	{		
		return toAjax(orderCategoryService.updateOrderCategory(orderCategory));
	}
	
	/**
	 * 删除订单品类
	 */
	@ApiOperation("删除订单品类")
	@RequiresPermissions("system:orderCategory:remove")
	@Log(title = "订单品类", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(orderCategoryService.deleteOrderCategoryByIds(ids));
	}
	
}
